package com.indCfeng.minio;

import io.minio.MinioClient;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * @author Cfeng
 * @date 2022/8/11
 */

@Configuration
@ConditionalOnClass(MinioClient.class) //只有存在MinioClient才加载配置类
@EnableConfigurationProperties(MinioConfigurationProperties.class)
@ComponentScan("com.indCfeng.minio")  //扫描加载Service
public class MinioConfiguration {

    @Resource
    private MinioConfigurationProperties minioConfigurationProperties;

    /**
     * 配置MinioClient对象， 通过factories扫描完成自动配置
     */
    @Bean
    public MinioClient minioClient() {
        return MinioClient.builder()
                .endpoint(minioConfigurationProperties.getEndpoint())
                .credentials(minioConfigurationProperties.getAccessKey(),minioConfigurationProperties.getSecretKey())
                .build();
    }
}
